package com.dmgis.qxfw.dataservice.businessservice.yysl.service.Impl;


import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByUpdate;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.soil_humidity;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.ActualData;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.MsgMediumSmallScale;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.yysl.pojo.NewTime;
import com.dmgis.qxfw.dataservice.businessservice.yysl.pojo.PublishRecord;
import com.dmgis.qxfw.dataservice.businessservice.yysl.pojo.QPF;
import com.dmgis.qxfw.dataservice.businessservice.yysl.service.IWaternfoService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.poi.ss.formula.functions.T;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service("WaterService")
public class WaterInfoServiceImpl implements IWaternfoService {

    ProcessRequestController pc = new ProcessRequestController();

    @Override
    public MsgMediumSmallScaleKey getSmallScaleNewDate() {
        // TODO 获取自动站最新时间
        MsgMediumSmallScaleKey newestDate = new MsgMediumSmallScaleKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observtime,'yyyy-MM-dd HH24:MI:SS') as observtime"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            System.out.println(message);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScaleKey>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setObservTime(DateTime.now().toDate());
        }
        return newestDate;
    }


    @Override
    public List<DZWarning> getDZAreaDoc(String docid) {
        // TODO 获取地灾预警信息
        List<dz_warning> listData = new ArrayList<dz_warning>();
        List<DZWarning> resultList = new ArrayList<DZWarning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(docid)) {
            strWhere.append(String.format(" and docid='%s'", docid));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setLimit(1);
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc"});
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<dz_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (dz_warning dzWarn : listData) {
                DZWarning dzWarning = new DZWarning();
                dzWarning.setDocid(dzWarn.getDocid());
                dzWarning.setDateChar(dzWarn.getDatechar());
                dzWarning.setPos(dzWarn.getPos());
                dzWarning.setGradeArea2(dzWarn.getGradearea2());
                dzWarning.setGradeArea3(dzWarn.getGradearea3());
                dzWarning.setGradeArea4(dzWarn.getGradearea4());
                dzWarning.setGradeArea5(dzWarn.getGradearea5());
                dzWarning.setDocpath(dzWarn.getDocpath());
                resultList.add(dzWarning);
            }
        }
        return resultList;
    }

    @Override
    public DZWarning getDZWarningNewDate() {
        // TODO 获取预警查询时间
        DZWarning result = new DZWarning();
        sl_warning newestDate = new sl_warning();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd HH24:MI:SS') as dateChar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setDatechar(DateTime.now().toDate());
        }
        if (newestDate != null) {
            result.setDateChar(newestDate.getDatechar());
        }
        return result;
    }

    @Override
    public DZWarning getPageNewDate(String table) {
        // TODO 获取预警查询时间
        DZWarning result = new DZWarning();
        sl_warning newestDate = new sl_warning();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"replace(datechar, '/', '-')  datechar "};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", table);
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setDatechar(DateTime.now().toDate());
        }
        if (newestDate != null) {
            result.setDateChar(newestDate.getDatechar());
        }
        return result;
    }

    @Override
    public List<DZWarning> getDZWarning(DZwarningSearch warnsearch) {
        // TODO 获取预警
        List<sl_warning> listData = new ArrayList<sl_warning>();
        List<DZWarning> resultList = new ArrayList<DZWarning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("docid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("State");
        columns.add("ShFlag");
        columns.add("GradeArea3");
        columns.add("GradeArea4");
        columns.add("GradeArea5");
        columns.add("Pos");
        columns.add("Docpath");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (warnsearch.getDatechar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", warnsearch.getDatechar()));
        }
        if (warnsearch.getStartDate() != null) {
            strWhere.append(String.format(" and datechar>='%s'", warnsearch.getStartDate()));
        }
        if (warnsearch.getEndDate() != null) {
            strWhere.append(String.format(" and datechar<='%s'", warnsearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(warnsearch.getType())) {
            strWhere.append(String.format(" and warningtype='%s'", warnsearch.getType()));
        }
        strWhere.append(String.format(" and state>=3"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (sl_warning dz_warn : listData) {
                DZWarning DZwarning = new DZWarning();
                DZwarning.setDocid(dz_warn.getDocid());
                DZwarning.setDateChar(dz_warn.getDatechar());
                DZwarning.setGradeArea3(dz_warn.getGradearea3());
                DZwarning.setGradeArea4(dz_warn.getGradearea4());
                DZwarning.setGradeArea5(dz_warn.getGradearea5());
                DZwarning.setState(dz_warn.getState());
                DZwarning.setShFlag(dz_warn.getShflag());
                DZwarning.setPos(dz_warn.getPos());
                DZwarning.setDocpath(dz_warn.getDocpath());
                resultList.add(DZwarning);
            }
        }
        return resultList;
    }


    @Override
    public List<Danger_warning> getMountainFlood(DZwarningSearch warnsearch) {
        // TODO 获取预警
        List<Danger_warning> listData = new ArrayList<Danger_warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"id,category,datatype,type,docid,gradearea1,gradearea2," +
                "gradearea3,gradearea4,docpath,picturepath,txtpath,to_char(to_timestamp(datechar,'yyyy-MM-dd hh24:mi:ss'), 'yyyy-MM-dd')  as  datechar"});
        selectRequest.setSort(new String[]{"to_timestamp(datechar,'yyyy-MM-dd hh24:mi:ss')  desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (warnsearch.getDatechar() != null) {
            strWhere.append(String.format(" and dateChar='%tF'", warnsearch.getDatechar()));
        }
        if (warnsearch.getStartDate() != null) {
            strWhere.append(String.format(" and  to_timestamp(datechar,'yyyy-MM-dd hh24:mi:ss')>='%s'", warnsearch.getStartDate()));
        }
        if (warnsearch.getEndDate() != null) {
            strWhere.append(String.format(" and to_timestamp(datechar,'yyyy-MM-dd hh24:mi:ss') <='%s'", warnsearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(warnsearch.getType())) {
            strWhere.append(String.format(" and type='%s'", warnsearch.getType()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "danger_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Danger_warning>>() {
            });
            //构造filename属性 截取时间
            for (int i = 0; i < listData.size(); i++) {
                Danger_warning warning = listData.get(i);
                String fliepath = warning.getDocpath();
                int index2 = fliepath.lastIndexOf("\\");
                String filename = fliepath.substring(index2 + 1, fliepath.length());
                warning.setFilename(filename);
        }

        } catch (Exception e) {
            // TODO: handle exception
            return null;
        }
        if (listData != null && listData.size() > 0) {
            return listData;
        }
        return listData;
    }


    /*
      获取实况水位表
      需求:根据-stationname字段和时间排序的顺序 从water表中查找实况水位 -smallscalewaterstatus
     */
    @Override
    public List<reservoir_water_info> findWaterInfo(String stationname) {
        List<reservoir_water_info> resultList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("waterlevel");
        columns.add("stationid");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            strWhere.append(String.format("stationname ='%s'", stationname));
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_info>>() {
            });
        } catch (Exception e) {
            System.out.println("errror!");
        }
        return resultList;
    }
    /*
     获取淹没分析数据,显示预警等级
     */
    @Override
    public List<Flooded> findAllFlooded(String stationname, Double waterlev) {
        List<Flooded> resultList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("name");
        columns.add("stationName");
        columns.add("pos");
        columns.add("time");
        columns.add("people");
        columns.add("waterLev");
        columns.add("waterFlow");
        columns.add("warnlevel");
        columns.add("City");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            strWhere.append(String.format("stationname ='%s' and waterlev<%f", stationname, waterlev));
        } else {
            strWhere.append(String.format("waterlev<%f", waterlev));
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"waterlev desc"});
        if (!StringUtil.IsNullOrEmpty(stationname)){
            selectRequest.setLimit(1);
        }
        try {
            selectParam.put("method", "flooded");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            System.out.println(message);

//            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Flooded>>() {});
            Class<Flooded> clazz=Flooded.class;
            List<Flooded> a = new ArrayList<>();
            resultList = JsonUtil.jsonArrayStr2Entity(message,clazz);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("error!");
        }
        return resultList;
    }


    @Override
    public List<Flooded> getFloodPlan() {
        // TODO 防汛预案
        List<flooded> listData = new ArrayList<flooded>();
        List<Flooded> resultList = new ArrayList<Flooded>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("name");
        columns.add("stationName");
        columns.add("pos");
        columns.add("time");
        columns.add("people");
        columns.add("waterLev");
        columns.add("waterFlow");
        columns.add("WarnLevel");
        columns.add("City");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "flooded");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<flooded>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (flooded flood : listData) {
                Flooded flooded = new Flooded();
                flooded.setId(flood.getId());
                flooded.setName(flood.getName());
                flooded.setStationName(flood.getStationname());
                flooded.setPos(flood.getPos());
                flooded.setWaterLev(flood.getWaterlev());
                flooded.setWaterFlow(flood.getWaterflow());
                flooded.setWarnLevel(flood.getWarnlevel());
                flooded.setCity(flood.getCity());
                flooded.setPeople(flood.getPeople());
                resultList.add(flooded);
            }
        }
        return resultList;
    }


    @Override
    public List<WaterStation> getWaterStation() {
        // TODO 水文站
        List<water_station> listData = new ArrayList<water_station>();
        List<WaterStation> resultList = new ArrayList<WaterStation>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct STNM"};
        selectRequest.setColumns(columns);
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (water_station waters : listData) {
                WaterStation waterstation = new WaterStation();
                waterstation.setStnm(waters.getStnm());
                resultList.add(waterstation);
            }
        }
        return resultList;
    }

    @Override
    public List<WaterStation> getWaterStations(WaterStation selectKey) {
        // TODO 水文站经纬度
        List<water_station> listData = new ArrayList<water_station>();
        List<WaterStation> resultList = new ArrayList<WaterStation>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stnm");
        columns.add("lgtd");
        columns.add("lttd");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStnm())) {
            strWhere.append(String.format("and stnm='%s'", selectKey.getStnm()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (water_station waters : listData) {
                WaterStation waterstation = new WaterStation();
                waterstation.setStnm(waters.getStnm());
                waterstation.setLon(Double.parseDouble(waters.getLgtd()));
                waterstation.setLat(Double.parseDouble(waters.getLttd()));
                resultList.add(waterstation);
            }
        }
        return resultList;
    }

    @Override
    public List<DisasterPoint> getDPointCountys() {
        // TODO 县点
        List<county_point> listData = new ArrayList<county_point>();
        List<DisasterPoint> resultList = new ArrayList<DisasterPoint>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct name"};
        selectRequest.setColumns(columns);
        try {
            selectParam.put("method", "county_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<county_point>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (county_point county : listData) {
                DisasterPoint disasterpoint = new DisasterPoint();
                disasterpoint.setCountys(county.getName());
                resultList.add(disasterpoint);
            }
        }
        return resultList;
    }

    @Override
    public List<DisasterPoint> getDPointTypes() {
        // TODO 灾害类型
        List<potential_points> listData = new ArrayList<potential_points>();
        List<DisasterPoint> resultList = new ArrayList<DisasterPoint>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct disastertype"};
        selectRequest.setColumns(columns);
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (potential_points type : listData) {
                DisasterPoint disasterpoint = new DisasterPoint();
                disasterpoint.setTypes(type.getDis_type());
                resultList.add(disasterpoint);
            }
        }
        return resultList;
    }

    @Override
    public DHistory getDHistoryNewDate() {
        // TODO 历史灾情最新时间
        DHistory result = new DHistory();
        flood_disaster_history newestDate = new flood_disaster_history();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"disastertime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"disastertime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "flood_disaster_history");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<flood_disaster_history>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setDisastertime(DateTime.now().toDate() + "");
        }
        if (newestDate != null) {
            result.setDisastertime(newestDate.getDisastertime());
        }
        return result;
    }

    @Override
    public List<DHistory> getDHistory(DHistorySearch selectKey) {
        // TODO 历史灾情
        List<flood_disaster_history> listData = new ArrayList<flood_disaster_history>();
        List<DHistory> resultList = new ArrayList<DHistory>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("disasterid");
        columns.add("disastername");
        columns.add("address");
        columns.add("disastertime");
        columns.add("disasterpopulation");
        columns.add("disasterproperty");
        columns.add("deathpopulation");
        columns.add("disasterlevel");
        columns.add("lon");
        columns.add("lat");
        columns.add("remarks");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setLimit(1);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getTypes())) {
            strWhere.append(String.format("and disasterlevel='%s'", selectKey.getTypes()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "flood_disaster_history");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<flood_disaster_history>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listData != null && listData.size() > 0) {
            for (flood_disaster_history floodhistory : listData) {
                DHistory dhistory = new DHistory();
                dhistory.setDisasterid(floodhistory.getDisasterid());
                dhistory.setDisastername(floodhistory.getDisastername());
                dhistory.setAddress(floodhistory.getAddress());
                dhistory.setDisastertime(floodhistory.getDisastertime());
                dhistory.setDisasterpopulation(floodhistory.getDisasterpopulation());
                dhistory.setDisasterproperty(floodhistory.getDisasterproperty());
                dhistory.setDeathpopulation(floodhistory.getDeathpopulation());
                dhistory.setDisasterlevel(floodhistory.getDisasterlevel());
                dhistory.setLon(floodhistory.getLon());
                dhistory.setLat(floodhistory.getLat());
                dhistory.setRemarks(floodhistory.getRemarks());
                resultList.add(dhistory);
            }
        }
        return resultList;
    }

    @Override
    public List<potential_points> getDPoint(DPoint Dpoint) {
        // TODO 灾点查询
        List<potential_points> listData = new ArrayList<potential_points>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(Dpoint.getCounty())) {
            strWhere.append(String.format(" and county='%s'", Dpoint.getCounty()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_type())) {
            strWhere.append(String.format(" and dis_type='%s'", Dpoint.getDis_type()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_level())) {
            strWhere.append(String.format(" and dis_level='%s'", Dpoint.getDis_level()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDanger_level())) {
            strWhere.append(String.format(" and danger_level='%s'", Dpoint.getDanger_level()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getCity())) {
            strWhere.append(String.format(" and city='%s'", Dpoint.getCity()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<Rainwatershed> getRainWater() {
        // TODO 面雨量流域
        List<rain_water_shed> listRainData = new ArrayList<rain_water_shed>();
        List<Rainwatershed> resultList = new ArrayList<Rainwatershed>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("name");
        columns.add("coordinate");
        columns.add("centerpointx");
        columns.add("centerpointy");
        columns.add("type");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "rain_water_shed");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listRainData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<rain_water_shed>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listRainData != null && listRainData.size() > 0) {
            for (rain_water_shed rainwatershed : listRainData) {
                Rainwatershed rainwater = new Rainwatershed();
                rainwater.setName(rainwatershed.getName());
                rainwater.setCoordinate(rainwatershed.getCoordinate());
                rainwater.setCenterpointx(rainwatershed.getCenterpointx());
                rainwater.setCenterpointy(rainwatershed.getCenterpointy());
                rainwater.setType(rainwatershed.getType());
                resultList.add(rainwater);
            }
        }
        return resultList;
    }

    @Override
    /*按照乡镇获取面雨量*/
    public List<country_point> getCountry() {
        List<country_point> listRainData = new ArrayList<country_point>();

        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "country_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listRainData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<country_point>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return listRainData;
    }

    @Override
    public List<MsgMediumSmallScale> getSumRain(SRainfallSearch srainfallsearch) {
        // TODO 各站点雨量
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        List<MsgMediumSmallScale> resultList = new ArrayList<MsgMediumSmallScale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("cast(sum(cast(rain as float)) as numeric(18,1)) as rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"Rain desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (srainfallsearch.getStartDate() != null) {
            strWhere.append(String.format(" and observtime>='%s'", srainfallsearch.getStartDate()));
        }
        if (srainfallsearch.getEndDate() != null) {
            strWhere.append(String.format(" and observtime<='%s'", srainfallsearch.getEndDate()));
        }
        strWhere.append(" and rain <> -65535");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(" and city like '"+DbConfig.CITY+"%' ");
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (msgmediumsmallscale msg : listData) {
                MsgMediumSmallScale smallscale = new MsgMediumSmallScale();
                smallscale.setStationID(msg.getStationid());
                smallscale.setStationname(msg.getStationname());
                smallscale.setLon(msg.getLongitude());
                smallscale.setLat(msg.getLatitude());
                smallscale.setAmassRain(msg.getRain());
                resultList.add(smallscale);
            }
        }
        return resultList;
    }

    @Override
    public List<MsgMediumSmallScale> getDSumRain(SRainfallSearch srainfallsearch) {
        // TODO 单时间各站点雨量
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        List<MsgMediumSmallScale> resultList = new ArrayList<MsgMediumSmallScale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("cast(sum(cast(Rain as float)) as numeric(18,1)) as Rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"Rain desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (srainfallsearch.getStartDate() != null) {
            strWhere.append(String.format(" and observtime='%s'", srainfallsearch.getStartDate()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(" and rain <> -65535");
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (msgmediumsmallscale msg : listData) {
                MsgMediumSmallScale smallscale = new MsgMediumSmallScale();
                smallscale.setStationID(msg.getStationid());
                smallscale.setStationname(msg.getStationname());
                smallscale.setLon(msg.getLongitude());
                smallscale.setLat(msg.getLatitude());
                smallscale.setAmassRain(msg.getRain());
                resultList.add(smallscale);
            }
        }
        return resultList;
    }

    @Override
    public List<TownshipForecast> getYBRainfall(TownshipForecastKey newestDate) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("cast(Rain as numeric(18,1)) as Rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        //条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", newestDate.getNTimes(),
                    newestDate.getNTimes() - 12));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecasttemp");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public String getProductID(String docpath) {
        // TODO Auto-generated method stub
        List<base_product> listData = new ArrayList<base_product>();
        String result = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(docpath)) {
            strWhere.append(String.format("productname='%s'", docpath));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (base_product dzWarn : listData) {
                result = dzWarn.getId().toString();
            }
        }
        return result;
    }

    @Override
    public List<sl_warning> getSLWarning() {
        List<sl_warning> listData = new ArrayList<sl_warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setSort(new String[]{"datechar desc", "docid desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public Date getWaterNewDate() {
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(latestobservetime, 'yyyy-MM-dd HH24:MI:SS') as latestobservetime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"latestobservetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "water");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            }).get(0).getLatestobservetime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public List<water> getWaterSta() {
        List<water> dataList = new ArrayList<water>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"distinct stationname,stationid"});
        try {
            selectParam.put("method", "water_obsrv_sta_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<water_station> getWaterSta2() {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"distinct stnm,stcd"});
        selectRequest.setParam("addvcd like '"+DbConfig.advCode.substring(0,4)+"%' and (sttp='ZQ' or sttp='ZZ')");
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exceptioninitScalePage
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<water_station> waterQuery(String startDate, String endDate, String countys) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("lgtd");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stnm");
        columns.add("lttd");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if(!StringUtil.IsNullOrEmpty(countys)){
            //selectRequest.setParam(" addvcd like'" + DbConfig.advCode.substring(0, 4) + "%' and (sttp='ZQ' or sttp='ZZ') and stnm like '"+countys+"%'");
            selectRequest.setParam(" addvcd like'" + DbConfig.advCode.substring(0, 4) + "%' and (sttp='ZQ' or sttp='ZZ')");
        }else {
            selectRequest.setParam(" addvcd like'" + DbConfig.advCode.substring(0, 4) + "%' and (sttp='ZQ' or sttp='ZZ')");
        }
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water> dataList1 = new ArrayList<water>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    columns = new ArrayList<String>();
                    columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
                    columns.add("stationname");
                    columns.add("latestobservetime");
                    columns.add("smallscalewaterstatus");
                    selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                    // 拼接where字段
                    StringBuilder strWhere = new StringBuilder();
                    int whereCount = 0;
                    if (!StringUtil.IsNullOrEmpty(countys)) {
                        whereCount++;
                        strWhere.append(String.format("latestobservetime >='%s'", startDate));
                    }
                    if (!StringUtil.IsNullOrEmpty(countys)) {
                        strWhere.append(String.format(" and latestobservetime <='%s'", endDate));
                    }
                    strWhere.append(" and stationname = '" + w.getStnm().trim() + "'");
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strWhere = strWhere.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    selectRequest.setSort(new String[]{"latestobservetime desc"});
                    try {
                        selectParam.put("method", "water");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
                        });
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water sta : dataList1) {
                                w.setTime(new DateTime(sta.getLatestobservetime()).toDateTimeString());
                                w.setStationid(sta.getStationid());
                                w.setLon(w.getLgtd());
                                w.setLat(w.getLttd());
                                w.setStnm(w.getStnm().trim());
                                w.setBsnm(sta.getSmallscalewaterstatus().toString());
                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<water> qxWaterQuery(ActualElemQuery elemQuery) {
        List<ActualData> resultList = new ArrayList<ActualData>();
        List<water> dataList = new ArrayList<water>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();

        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stid AS stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stnm AS stationname");
        columns.add("stadr AS smallscalewaterstatus");
        columns.add("time AS latestobservetime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));

        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("time >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and time <='%tF %tT'", endDate, endDate));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stcd in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "water");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public List<water> firstWaterQuery() {
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns1 = new String[]{"to_char(latestobservetime, 'yyyy-MM-dd HH24:MI:SS') as latestobservetime"};
        selectRequest.setColumns(columns1);
        selectRequest.setSort(new String[]{"latestobservetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "water");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            }).get(0).getLatestobservetime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        List<water> dataList = new ArrayList<water>();
        selectParam = new HashMap<String, String>();
        selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        columns.add("latestobservetime");
        columns.add("smallscalewaterstatus");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (date != null) {
            strWhere.append(String.format("latestobservetime ='%tF %tT'", date, date));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "water");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water w : dataList) {
                    List<water_obsrv_sta_info> dataList1 = new ArrayList<water_obsrv_sta_info>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    columns = new ArrayList<String>();
                    columns.add("longitude");// pg字段大小写不敏感的话，默认全部转换成小写模式
                    columns.add("stationname");
                    columns.add("latitude");
                    selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                    selectRequest.setParam("stationname = '" + w.getStationname() + "'");
                    try {
                        selectParam.put("method", "water_obsrv_sta_info");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = pc.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_obsrv_sta_info>>() {
                        });
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water_obsrv_sta_info sta : dataList1) {
                                w.setLon(sta.getLongitude());
                                w.setLat(sta.getLatitude());
                                w.setTime(new DateTime(w.getLatestobservetime()).toDateTimeString());
                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    /**
     * 取得水库列表
     */
    @Override
    public List<reservoir> getReservoir() {
        RequestDataBySelect query = new RequestDataBySelect();
        List<reservoir> dList = new ArrayList<reservoir>();
        Map<String, String> paraMap = new HashMap<String, String>();
        query.setParam("RANGE <>''");
        try {
            paraMap.put("method", "reservoir");
            paraMap.put("sqlType", "select");
            paraMap.put("advCode", DbConfig.advCode);
            paraMap.put("param", JsonUtil.object2Json(query));
            String message = pc.processRequest(paraMap);
            dList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dList;
    }


    /**
     * 获取应急点
     *
     * @param
     * @return
     * @author ymf
     * @date 2019/9/18
     **/
    @Override
    public List<Emergency> getEmpoint(DZQuery dzQuery) {
        List<emergency> listData = new ArrayList<emergency>();
        List<Emergency> resultList = new ArrayList<Emergency>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (dzQuery.getStartDate() != null) {
            whereCount++;
            strWhere.append(String.format("datetime>='%s'", dzQuery.getStartDate()));
        }
        if (dzQuery.getEndDate() != null) {
            strWhere.append(String.format(" and datetime<='%s'", dzQuery.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(dzQuery.getType())) {
            strWhere.append(String.format(" and type='山洪灾害'"));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datetime desc"});
        try {
            selectParam.put("method", "emergency");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<emergency>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (listData != null && listData.size() > 0) {
            for (emergency em : listData) {
                Emergency emy = new Emergency();
                emy.setDatetime(sdf.format(em.getDatetime()));
                emy.setId(em.getId());
                emy.setLongitude(em.getLongitude());
                emy.setLatitude(em.getLatitude());
                emy.setTitle(em.getTitle());
                emy.setType(em.getType());
                emy.setDocpath(em.getDocpath());
                resultList.add(emy);
            }
        }
        return resultList;
    }

    @Override
    public List<water_station> initReservoirInfo() {
        List<water_station> resultList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stcd");
        columns.add("stnm");
        columns.add("lgtd");
        columns.add("lttd");
        // columns.add("dtrange");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        String s = DbConfig.advCode.substring(0, 4);

        selectRequest.setParam("addvcd like '" + s + "%' AND sttp = 'PP'");
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }


    //获取水库入库流量预报结果信息
    @Override
    public List<reservoir_water_fcst> getInboundFlowFcstInfo(reservoir_water_fcst selectKey) throws ParseException {
        String datechar = selectKey.getDatechar() + " 00:00:00";
        String timechar = selectKey.getTimechar();
        String ntimes = selectKey.getNtimes();
        List<reservoir_water_fcst> resultList = new ArrayList<reservoir_water_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("datechar");
        columns.add("timechar");
        columns.add("ntimes");
        columns.add("inputflow");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam(String.format("datechar = '%s' and timechar = '%s' and ntimes='%s'", datechar, timechar, ntimes));
        try {
            selectParam.put("method", "reservoir_water_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<reservoir_water_fcst> getInboundFlowFcstInfoDays(reservoir_water_fcst selectKey) throws ParseException {
        String datechar = selectKey.getDatechar() + " 00:00:00";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = format.parse(datechar);
//        date.setTime(date.getTime() - 7 *24* 60 * 60 * 1000);
//        String startDate = new DateTime(date).toDateTimeString();
        String startDate = new DateTime(date).AddDays(-7).toDateTimeString();
        String timechar = selectKey.getTimechar();
        String ntimes = selectKey.getNtimes();
        String stationname = selectKey.getStationname();
        List<reservoir_water_fcst> resultList = new ArrayList<reservoir_water_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("datechar");
        columns.add("timechar");
        columns.add("ntimes");
        columns.add("inputflow");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam(String.format("datechar >= '%s' and datechar <= '%s' and timechar = '%s' and ntimes='%s' and stationname like '%s%%'",startDate, datechar, timechar, ntimes,stationname));
        try {
            selectParam.put("method", "reservoir_water_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    //获取水库灌溉指数预报信息
    @Override
    public List<reservoir_irrigation_index_fcst> getIrrigationFcstInfo(reservoir_irrigation_index_fcst selectKey) {
        String datechar = selectKey.getDatechar();
        String timechar = selectKey.getTimechar();
        Integer ntimes = selectKey.getNtimes();
        List<reservoir_irrigation_index_fcst> resultList = new ArrayList<reservoir_irrigation_index_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("datechar = '%s' and timechar = '%s' and ntimes='%s'", datechar, timechar, ntimes));
        try {
            selectParam.put("method", "reservoir_irrigation_index_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_irrigation_index_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<sl_warning> getAuditingWarn() {
        List<sl_warning> sl_warnings = new ArrayList<>();

        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"docid,to_char(datechar,'yyyy-MM-dd') as datechar, timechar,warning_id, warningtype, First,gradearea3 ,gradearea4,gradearea5,PosArea3, PosArea4, PosArea5,pos"});
        selectRequest.setSort(new String[]{"docid desc"});
        selectRequest.setParam(String.format("State='0' and to_char(datechar,'yyyy-MM-dd')>='%s'", DateTime.now().toDateString()));
        Map<String, String> selectParam = new HashMap<String, String>();
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            sl_warnings = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            }, "yyyy-MM-dd");
        } catch (Exception e) {
            System.out.println("error!");
        }

        return sl_warnings;
    }

    @Override
    public List<sl_warning> getWarnmessage(String id) {
        List<sl_warning> sl_warnings = new ArrayList<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"docid,to_char(datechar,'yyyy-MM-dd') as datechar, timechar, pos,warning_id, warningtype, First,gradearea3 ,gradearea4,gradearea5,PosArea3, PosArea4, PosArea5"});
        selectRequest.setSort(new String[]{"docid desc"});
        selectRequest.setParam(String.format("docid='%s'", id));
        Map<String, String> selectParam = new HashMap<String, String>();
        try {
            selectParam.put("method", "sl_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            sl_warnings = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_warning>>() {
            }, "yyyy-MM-dd");
        } catch (Exception e) {
            System.out.println("error!");
        }
        return sl_warnings;

    }


    /****
     * 得到水利设施
     * @return
     */
    @Override
    public List<water_facilities> getFacilities() {
        List<water_facilities> sl_warnings = new ArrayList<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<String, String>();
        try {
            selectParam.put("method", "water_facilities");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            sl_warnings = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_facilities>>() {
            });
            for (water_facilities sl_warning : sl_warnings) {
                sl_warning.setStationname(sl_warning.getStationname().trim());
            }
        } catch (Exception e) {
            System.out.println("error!");
        }
        return sl_warnings;
    }

    /***
     * 得到水利灾点查询
     * @param county
     * @return
     */
    @Override
    public List<potential_points> getSLPoint(String county) {
        List<potential_points> listData = new ArrayList<potential_points>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(county)) {
            strWhere.append(String.format(" city like '%s%%'", DbConfig.CITY));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public String updOpinion(sl_warning sl_warning, String docid) {
        String result = "";
        try {
            com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.sl_warning sl_warnings = new sl_warning();
            sl_warnings.setState(sl_warning.getState());
            sl_warnings.setShideas(sl_warning.getShideas());
            Map<String, String> updateParam = new HashMap<String, String>();
            RequestDataByUpdate<String, com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.sl_warning> updateRequest = new RequestDataByUpdate<String, com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.sl_warning>();
            updateRequest.setData(sl_warnings);
            updateRequest.setParam(String.format("docid='%s'", docid));
            updateParam.put("method", "sl_warning");
            updateParam.put("sqlType", "update");
            updateParam.put("advCode", DbConfig.advCode);
            updateParam.put("param", JsonUtil.object2Json(updateRequest));
            result = pc.processRequest(updateParam);
        } catch (Exception e) {

        }
        return result;
    }

    /***
     * 河道水位监控
     * @return
     */
    @Override
    public Object GetRiverWarnMoniInfo() {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
        String strDate2 = currentTime.toDateTimeString(); // 开始时间
        List<water> infos = new ArrayList<water>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        //dataBySelect.setParam("time  between '" + strDate1 + "' and '" + strDate2 + "' and county  like '%"+DbConfig.CITY+"%' and  smallscalewaterstatus > warningwaterstatus");
        dataBySelect.setParam("time  between '" + strDate1 + "' and '" + strDate2 + "' and county  like '%"+DbConfig.CITY+"%' ");
        dataBySelect.setSort(new String[]{"time desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "water");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water>>() {
                });
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /****
     * 获取预警信号  当天
     * @return
     */
    @Override
    public Object GetWarnSignalInfo() {
        String result = "";
        try {
            String yjLevel = "";
            String color = "";
            DateTime currentTime = DateTime.now();
            String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
            String strDate2 = currentTime.toDateTimeString(); // 开始时间
            String type = ""; // 类型
            String level = ""; // 级别
            String bFree = "0"; // 是否解除

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam("AnnouncedTime BETWEEN '" + strDate1 + "' AND '" + strDate2 + "' AND city like '"+DbConfig.CITY+"%' AND 1=1 AND 2=2 AND 3=3");

            dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "type in ('暴雨','暴雪','强对流','高温')"));
            if (!StringUtil.IsNullOrEmpty(level) && !level.equals("全部")) {
                dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "Color LIKE '%" + level + "%'"));
            }
            if (!StringUtil.IsNullOrEmpty(bFree)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "bFree='" + bFree + "'"));
            }
            dataBySelect.setSort(new String[]{"AnnouncedTime DESC"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "warn_signal_info");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<warn_signal_info> infos = new ArrayList<warn_signal_info>();
            infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<warn_signal_info>>() {
            });

            // 执行查询

            result = "{\"message\": \"查询成功\",\n" +
                    "\"data\": [";
            if (infos != null && infos.size() > 0) {
                for (warn_signal_info info : infos) {
                    result += "{";
                    result += "\"id\":\"" + info.getId() + "\",";
                    result += "\"area\":\"" + info.getArea() + "\",";
                    result += "\"type\":\"" + info.getType() + "\",";//
                    yjLevel = info.getColor();
                    switch (yjLevel) {
                        case "红色":
                            color = "255";
                            break;
                        case "橙色":
                            color = "42495";
                            break;
                        case "黄色":
                            color = "65535";
                            break;
                        case "蓝色":
                            color = "16711680";
                            break;
                    }
                    result += "\"level\":\"" + yjLevel + "\",";
                    result += "\"color\":\"" + color + "\",";
                    result += "\"county\":\"" + info.getCounty() + "\",";
                    result += "\"standard\":\"" + info.getStandard() + "\",";
                    result += "\"defenseGuide\":\"" + info.getDefenseguide() + "\",";
                    result += "\"announcedTime\":\""
                            + new DateTime(info.getAnnouncedtime()).toDateTimeString("yyyy-MM-dd HH:mm:ss") + "\",";
                    result += "\"signatory\":\"" + info.getSignatory() + "\",";
                    result += "\"watch\":\"" + info.getWatch() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"bFree\":\"" + info.getBfree() + "\",";
                    result += "\"jcpath\":\"" + info.getJcpath() + "\",";
                    result += "\"y2path\":\"" + info.getY2path() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"jb\":\"" + Integer.parseInt(info.getJb().toString()) + "\"";
                    result += "},";
                }
                if (result.endsWith(","))
                    result = result.subSequence(0, result.length() - 1) + "],\"status\": true}";
                else
                    result = result + "],\"status\": true}";
            } else {
                return new ResultObj("查询成功", "[]", true);
            }


        } catch (Exception e) {
            e.printStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return result;
    }


    /****
     * 获取预警信号  文字滚动
     * @return
     */
    @Override
    public List<warning> GetWarnSignalInfoWenZi() {
        List<warning_area_bind> list = new ArrayList<warning_area_bind>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"name"});
        selectRequest.setParam("status = '1'and amenu is null and bmenu is null");
        try {
            selectParam.put("method", "warning_area_bind");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning_area_bind>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        String gzArea="";
        int i=0;
        for(warning_area_bind warn :list){
            gzArea+=" area like '%"+warn.getName()+"%' or";
            if(warn.getName().contains(DbConfig.COUNTY) ){
                i++;
            }
        }
        if(gzArea.endsWith("or")){
            gzArea = gzArea.substring(0, gzArea.length() - 2);
        }
        List<warning> resultList = new ArrayList<warning>();
        selectParam = new HashMap<String, String>();
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        try {
            String yjLevel = "";
            String color = "";
            DateTime currentTime = DateTime.now();
            String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
            String strDate2 = currentTime.toDateTimeString(); // 开始时间
            String type = ""; // 类型
            String level = ""; // 级别
            String bFree = "0"; // 是否解除

            dataBySelect.setParam("AnnouncedTime BETWEEN '" + strDate1 + "' AND '" + strDate2 + "' AND city like '%"+ DbConfig.CITY +"%' AND 1=1 AND 2=2 AND 3=3");

            dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "type in ('暴雨','暴雪','强对流','高温')"));
            if (!StringUtil.IsNullOrEmpty(level) && !level.equals("全部")) {
                dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "Color LIKE '%" + level + "%'"));
            }
            if (!StringUtil.IsNullOrEmpty(bFree)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "bFree='" + bFree + "'"));
            }
            dataBySelect.setSort(new String[]{"AnnouncedTime DESC"});
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(dataBySelect));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }
    /***
     * 超警戒水位查询
     * @param stationname
     * @return
     */
    @Override
    public Object GetWaterWarnMoniInfo(String stationname) {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
        String strDate2 = currentTime.toDateTimeString();
        // 开始时间
        List<reservoir_water_info> infos = new ArrayList<reservoir_water_info>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("observtime between '" + strDate1 + "' and '" + strDate2 + "' and 1 = 1 and  waterlevel > limited_waterlv");
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "stationname LIKE '%" + stationname + "%'"));
        }
        dataBySelect.setSort(new String[]{"observtime desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "reservoir_water_info");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<reservoir_water_info>>() {
                });
                for (reservoir_water_info info : infos)
                    info.setWaterflow((float) (info.getWaterlevel() - info.getLimited_waterlv()));
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 城镇预报站点信息
     * @return
     */
    @Override
    public List<township_station> getloadCityStation() {
        // TODO 城镇预报站点信息
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and stationid = '"+DbConfig.STATIONID+"'"));

        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid desc"});
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public forecastinfotemp getInitCityMaxTime(String name, String county) {
        // TODO 获取城镇预报最新时间
        forecastinfotemp result = new forecastinfotemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            if (name.contains(county)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "township_forecast");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    /***
     * 城镇预报查询
     * @param selectKey
     * @param type
     * @return
     */
    @Override
    public List<forecastinfotemp> getCityForecast(forecastinfotemp selectKey, String type) {
        // TODO 城镇预报查询
        List<forecastinfotemp> resultList = new ArrayList<forecastinfotemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        columns.add("maxhumid");
        columns.add("datechar");
        columns.add("timechar");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (type.equals("weather") || type == "weather") {
            selectRequest.setLimit(1);
        }
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar='%s'", selectKey.getTimechar()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc", "ntimes asc"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (resultList.size() == 0) {
                selectRequest.setSort(new String[]{"timechar desc"});
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /****
     * 得到最近站点未来七天天气预报
     * @param newestDate
     * @param lon
     * @param lat
     * @return
     */
    @Override
    public List<TownshipForecast> getNearStaThreeForecast(TownshipForecastKey newestDate, String lon, String lat) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationid"});
        selectRequest.setSort(new String[]{"(longitude - " + Double.parseDouble(lon) + ") * (longitude - " + Double.parseDouble(lon) + ") + (latitude - " + Double.parseDouble(lat) + ") * (latitude - " + Double.parseDouble(lat) + ")"});
        selectRequest.setLimit(1);
        String stationID = "";
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<township_station> result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
            if (result != null && result.size() > 0)
                stationID = result.get(0).getStationid();
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (StringUtil.IsNullOrEmpty(stationID))
            return resultList;
        selectParam = new HashMap<String, String>();
        selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(stationID)) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", stationID));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 168,
                    0));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%' and areaname ='%s'", DbConfig.CITY, DbConfig.COUNTY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecasttemp");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /***
     * 获取天气
     * @return
     */
    @Override
    public Object getWeather() {
        List<township_forecasttemp> list = new ArrayList<>();
        List<township_forecasttemp> listResult = new ArrayList<township_forecasttemp>();
        String name = "";
        String county = "";
        Map<Object, String> maps = getNeartime("township_forecast_province");
        forecastinfotemp infotemp = getInitCityMaxTime(name, county);
        String timechar = infotemp.getTimechar().trim();
        String datechar = new DateTime(infotemp.getDatechar()).toDateString().trim();
        //修改改为单独乡镇
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setSort(new String[]{"stationid asc"});
        selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
        if (maps.size() > 0) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "datechar ='" + datechar + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "timechar ='" + timechar + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("3=3", "ntimes <='24'"));
            selectRequest.setParam(selectRequest.getParam().replace("4=4", "stationid ='51328'"));
            //selectRequest.setParam(selectRequest.getParam().replace("4=4", "stationid ='"+DbConfig.STATIONIDYB+"'"));

        }
        try {
            selectParam.put("method", "forecastinfo");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<forecastinfotemp> list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (list1.size() > 0) {
                township_forecasttemp fcst12 = new township_forecasttemp();
                forecastinfotemp fcst = list1.get(0);
                fcst12.setStationid(fcst.getStationid());
                fcst12.setStationname(fcst.getStationname());
                double maxTemp = fcst.getMaxtemp();
                double minTemp = fcst.getMintemp();
                fcst12.setMaxtemp(maxTemp);
                fcst12.setMintemp(minTemp);
                String strWeather1 = "";
                strWeather1 = fcst.getWeather1().toString().trim();
                String strWeather2 = "";
                strWeather2 = fcst.getWeather2().toString().trim();
                String weatherCode1 = String.format("%02d", Integer.parseInt(
                        WebCtrlData.WeatherNameToPicPath(strWeather1)));
                String weatherCode2 = String.format("%02d", Integer.parseInt(
                        WebCtrlData.WeatherNameToPicPath(strWeather2)));
                String strTime = maps.get("2").toString();
                String strImgPic1 = "<img height='32' width='32' src='images/weatherDay/" + weatherCode1
                        + ".gif'>";
                String strImgPic2 = "<img height='32' width='32' src='images/weatherNight/" + weatherCode2
                        + ".gif'>";
                if (strTime == "20") {
                    strImgPic1 = "<img height='32' width='32' src='images/weatherNight/" + weatherCode1 + ".gif'>";
                    strImgPic2 = "<img height='32' width='32' src='images/weatherDay/" + weatherCode2 + ".gif'>";
                }
                fcst12.setImgpath(strImgPic1);
                fcst12.setImgpath1(strImgPic2);
                listResult.add(fcst12);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }

        //乡镇
        selectParam = new HashMap<String, String>();
        selectRequest = new RequestDataBySelect();
        selectRequest.setSort(new String[]{"stationid asc,ntimes asc"});
        selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4 and 5=5");
        if (maps.size() > 0) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "datechar ='" + maps.get("1") + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "timechar ='" + maps.get("2") + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("3=3", "ntimes <='24'"));
            selectRequest.setParam(selectRequest.getParam().replace("4=4", "stationid !='"+DbConfig.STATIONIDYB+"'"));
            selectRequest.setParam(selectRequest.getParam().replace("5=5", "city LIKE'"+DbConfig.CITY+"%'"));
        }
        try {
            selectParam.put("method", "township_forecast_province");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });

            if (list.size() > 0) {
                for (int i = 0; i < list.size(); i += 2) {
                    township_forecasttemp fcst12 = list.get(i);
                    township_forecasttemp fcst24 = list.get(i + 1);
                    township_forecasttemp fcst = new township_forecasttemp();
                    fcst.setStationid(fcst12.getStationid());
                    fcst.setStationname(fcst12.getStationname());
                    double maxTemp = fcst24.getMaxtemp();
                    double minTemp = fcst24.getMintemp();
                    fcst.setMaxtemp(maxTemp);
                    fcst.setMintemp(minTemp);
                    String strWeather1 = "";
                    strWeather1 = fcst12.getWeather1().toString().trim();
                    String strWeather2 = "";
                    strWeather2 = fcst24.getWeather1().toString().trim();
                    String weatherCode1 = WebCtrlData.WeatherNameToPicPath(strWeather1);
                    String weatherCode2 = WebCtrlData.WeatherNameToPicPath(strWeather2);
                    String strTime = maps.get("2").toString();
                    String strImgPic1 = "<img height='32' width='32' src='images/weatherDay/" + weatherCode1
                            + ".gif'>";
                    String strImgPic2 = "<img height='32' width='32' src='images/weatherNight/" + weatherCode2
                            + ".gif'>";
                    if (strTime == "20") {
                        strImgPic1 = "<img height='32' width='32' src='images/weatherNight/" + weatherCode1 + ".gif'>";
                        strImgPic2 = "<img height='32' width='32' src='images/weatherDay/" + weatherCode2 + ".gif'>";
                    }
                    fcst.setImgpath(strImgPic1);
                    fcst.setImgpath1(strImgPic2);
                    listResult.add(fcst);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return listResult;
    }

    /***
     * 查询最新一条数据
     * @return
     */
    public Map<Object, String> getNeartime(String method) {
        Map<Object, String> map = new HashMap<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setLimit(1);
        selectRequest.setSort(new String[]{"datechar desc"});
        List<township_forecasttemp> list = new ArrayList<>();
        try {
            selectParam.put("method", method);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String datechar = sdf.format(list.get(0).getDatechar());
            map.put("1", datechar);
            map.put("2", list.get(0).getTimechar());
        } catch (Exception e) {
            e.getStackTrace();
            return null;
        }
        return map;
    }

    /***
     * 土壤湿度
     * @param
     * @param startDate
     * @param endDate
     * @param level
     * @return
     */
    @Override
    public List<soil_humidity> soilChart(String stationId, String startDate, String endDate, String level) {
        List<soil_humidity> resultList = new ArrayList<soil_humidity>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(" stationid = '" + stationId + "'  and level='" + level + "'");
        selectRequest.setColumns(new String[]{"observetime"});
        selectRequest.setSort(new String[]{" observetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "soil_humidity");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
            });
            if (resultList != null && resultList.size() > 0) {
                Date cutime = resultList.get(0).getObservetime();
                startDate = new DateTime(cutime).AddHours(-23).toDateTimeString("yyyy-MM-dd HH");
                endDate = new DateTime(cutime).toDateTimeString("yyyy-MM-dd HH");
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                // 拼接where字段
                StringBuilder strWhere = new StringBuilder();
                int whereCount = 0;
                if (startDate != null) {
                    whereCount++;
                    strWhere.append(String.format(" observetime>='%s'", startDate + ":00:00"));
                }
                if (endDate != null) {
                    strWhere.append(String.format(" and observetime <='%s'", endDate + ":00:00"));
                }
                if (stationId != null) {
                    strWhere.append(" and stationid in ('" + stationId + "')");
                }
                //strWhere.append(" and level='" + level + "'");
                selectRequest.setSort(new String[]{" observetime asc,level"});
                // 获取查询字段
                List<String[]> columns = new ArrayList<>();
                selectRequest.setColumns(new String[]{"observetime", "relhumidity", "level"});
                if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                    strWhere = strWhere.replace(0, 4, "");
                }
                selectRequest.setParam(strWhere.toString());

                selectParam.put("method", "soil_humidity");
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
                });
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /****
     * 蒸发量  默认过去24小时
     * @param startDate
     * @param endDate
     * @param stationId
     * @return
     */
    @Override
    public List<msgmediumsmallscales> evaporationQuery(String startDate, String endDate, String stationId) {
        List<msgmediumsmallscales> resultList = new ArrayList<msgmediumsmallscales>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observtime>='%s'", startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <='%s'", endDate));
        }
        if (stationId != null) {
            strWhere.append(String.format(" and stationid='%s'", stationId));
        }
        selectRequest.setSort(new String[]{" to_char(observtime,'yyyy-MM-dd') asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setColumns(new String[]{"sum(evaporation) as evaporation", "to_char(observtime,'yyyy-MM-dd') as datechar", "stationname as stationname"});
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscales>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /***
     * 气温  默认过去24小时
     * @param endDate
     * @param stationname
     * @return
     */
    @Override
    public List<msgmediumsmallscales> tempQuery( String endDate, String stationname) {
        List<msgmediumsmallscales> resultList = new ArrayList<msgmediumsmallscales>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
//        if (startDate != null) {
//            whereCount++;
//            strWhere.append(String.format(" observtime>='%s'", startDate + ":00:00"));
//        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime ='%s'", endDate + ":00:00"));
        }
        if (stationname != null) {
//            String.format("city like '%s%%'", DbConfig.CITY)
            strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        }
        selectRequest.setSort(new String[]{" observtime asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscales>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /***
     * 干旱监测
     * @param startDate
     * @param endDate
     * @param stationname
     * @return
     */
    @Override
    public List<drought> droughtChart(String startDate, String endDate, String stationname) {
        List<drought> resultList = new ArrayList<drought>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observationdate>='%s'", startDate + ":00:00"));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observationdate <='%s'", endDate + ":00:00"));
        }
        if (stationname != null) {
            strWhere.append(String.format(" and stationid='%s'", stationname));
        }
        selectRequest.setSort(new String[]{" observationdate asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "drought");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<drought>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /***
     * 得到最新时间
     * @return
     */
    @Override
    public reservoir_water_fcst GetNewestDate() {
        reservoir_water_fcst newestDate = new reservoir_water_fcst();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd HH24:MI:SS') as datechar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "reservoir_water_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            System.out.println(message);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_fcst>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setDatechar(DateTime.now().toDateString());
            newestDate.setDatechar("20");
        }
        return newestDate;
    }

    /***
     * 得到最新时间
     * @return
     */
    @Override
    public reservoir_irrigation_index_fcst GetIrrigationNewestDate() {
        reservoir_irrigation_index_fcst newestDate = new reservoir_irrigation_index_fcst();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd HH24:MI:SS') as datechar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "reservoir_irrigation_index_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            System.out.println(message);
            newestDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_irrigation_index_fcst>>() {
            }).get(0);
        } catch (Exception e) {
            newestDate.setDatechar(DateTime.now().toDateString());
            newestDate.setDatechar("20");
        }
        return newestDate;
    }

    /***
     * 十天面雨量
     * @param selectKey
     * @return
     */
    @Override
    public List<area_rain> getSumAreaRain(SRainfallSearch selectKey) {
        DateTime now = DateTime.now();
        List<area_rain> rains = new ArrayList<area_rain>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"rain", "areaname"};
        selectRequest.setColumns(columns);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format("1=1"));
        if (!StringUtil.IsNullOrEmpty(selectKey.getType())) {
            strWhere.append(String.format(" and type='%s'", selectKey.getType()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getNtimes())) {
            strWhere.append(String.format(" and ntimes='%s'", selectKey.getNtimes()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getAreatype())) {
            strWhere.append(String.format(" and areatype='%s'", selectKey.getAreatype()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getStartDate())) {
            strWhere.append(String.format(" and observtime='%s'", selectKey.getStartDate()));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "area_rain");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            if(message.equals("[]")){
                strWhere = new StringBuilder();
                strWhere.append(String.format("1=1"));
                if (!StringUtil.IsNullOrEmpty(selectKey.getType())) {
                    strWhere.append(String.format(" and type='%s'", selectKey.getType()));
                }
                if (!StringUtil.IsNullOrEmpty(selectKey.getNtimes())) {
                    strWhere.append(String.format(" and ntimes='%s'", selectKey.getNtimes()));
                }
                if (!StringUtil.IsNullOrEmpty(selectKey.getAreatype())) {
                    strWhere.append(String.format(" and areatype='%s'", selectKey.getAreatype()));
                }
                if (!StringUtil.IsNullOrEmpty(selectKey.getStartDate())) {
                    String startDate = now.toDateString()+" "+now.AddHours(-1).GetHour()+":00:00";
                    strWhere.append(String.format(" and observtime='%s'", startDate));
                }
                selectRequest.setParam(strWhere.toString());
                selectParam.put("method", "area_rain");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
            }
            System.out.println(message);
            rains = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<area_rain>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
        }
        return rains;
    }
    /***
     * 获取菜单
     * @param reservoirid
     * @return
     */
    @Override
    public Object getmenu(String reservoirid){
        if (StringUtil.IsNullOrEmpty(reservoirid)) {
            return new ResultObj("查询失败", "单位ID为空", false);
        }
        String title = "";
        GongJuMenus gongJuMenus = new GongJuMenus();
        List<GongJuMenu> list = new ArrayList<>();

        List<reservoir_menu> list1 = new ArrayList<>();
        List<reservoir_menu> lists = new ArrayList<>();
        List<String> first = new ArrayList<>();
        List<String> second = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
        selectRequest.setSort(new String[]{"oneorder asc"});
        if (!StringUtil.IsNullOrEmpty(reservoirid)) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid ='" + reservoirid + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "oneorder is not null"));
            selectRequest.setParam(selectRequest.getParam().replace("3=3", "statu ='1'"));
            selectRequest.setParam(selectRequest.getParam().replace("4=4", "projecttype ='3'"));
        }
        try {
            selectParam.put("method", "reservoir_menu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_menu>>() {
            });
            for (reservoir_menu menu : list1) {
                first.add(menu.getMenu());
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
                selectRequest.setSort(new String[]{"twoorder asc"});
                String oneorder = menu.getOneorder();
                if (!StringUtil.IsNullOrEmpty(menu.getOneorder())) {
                    selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid ='" + reservoirid + "'"));
                    selectRequest.setParam(selectRequest.getParam().replace("2=2", "twoorder like'" + menu.getOneorder() + "-%" + "'"));
                    selectRequest.setParam(selectRequest.getParam().replace("3=3", "statu ='1'"));
                    selectRequest.setParam(selectRequest.getParam().replace("4=4", "projecttype ='3'"));
                    selectParam.put("method", "reservoir_menu");
                    selectParam.put("sqlType", "select");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String messages = pc.processRequest(selectParam);
                    lists = JsonUtil.jsonStr2TypeReference(messages, new TypeReference<List<reservoir_menu>>() {
                    });
                    for (reservoir_menu menus : lists) {
                        GongJuMenu gongJuMenu = new GongJuMenu();
                        gongJuMenu.setFirst(oneorder);
                        gongJuMenu.setName(menus.getMenu());
                        list.add(gongJuMenu);
                    }

                }
            }
            gongJuMenus.setTitle(title);
            gongJuMenus.setFirst(first);
            gongJuMenus.setSecond(second);
            gongJuMenus.setThird(list);
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功",gongJuMenus, true);
    }
    /**
     * 获取QPF
     * @return
     */
    @Override
    public List<QPF> getQPF(String data, String area) {
        List<QPF> source = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(" datechar ='" + data + "'  and ly='" + area + "'");
        selectRequest.setColumns(new String[]{"datechar", "type", "cast(value as float4) as value", "cast(ntimes as int2) as ntimes"});
        selectRequest.setSort(new String[]{"ntimes asc", "type asc"});
        selectParam.put("method", "qpf_data");
        try {
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            String message = pc.processRequest(selectParam);
            source = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<QPF>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return source;
    }

    /***
     * 获取产品类型
     * @return
     */
    @Override
    public List<job_model> getProductType()
    {
        List<job_model> jobs = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("twotype is not null and slcheck='1'");
        selectRequest.setColumns(new String[]{"id", "onetype","twotype", "slcheck"});
        selectRequest.setSort(new String[]{"onetype desc","id asc"});
        try {
            selectParam.put("method", "job_model");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            jobs = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<job_model>>() {
            });

        } catch (Exception e) {
            e.getStackTrace();
        }
        return jobs;
    }


    @Override
    public String getQPFNewDate() {
        // TODO 获取最新实况数据
        String date = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"year||'-'||month||'-'||day||' '||hour||':'||minute||':'||second as observtime"};//to_char(observtime, 'yyyy-MM-dd HH24:MI:SS')
        selectRequest.setColumns(columns);
        selectRequest.setParam("type='QPF'");
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "collect_time");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<NewTime>>() {
            }).get(0).getObservtime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public List<summary_product> getCommonWord(String bigtype, String smalltype) {
        List<summary_product> listData = new ArrayList<summary_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("forecasttime");
        columns.add("productname");
        columns.add("maketime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" status='1' ");
        int whereCount = 0;

        if (!StringUtil.IsNullOrEmpty(bigtype)) {
            whereCount++;
            strWhere.append(String.format(" and  producttype='%s'", bigtype));
        }
        if (!StringUtil.IsNullOrEmpty(smalltype)) {
            strWhere.append(String.format(" and producttype2='%s'", smalltype));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"maketime desc "});
        selectRequest.setLimit(5);
        try {
            selectParam.put("method", "summary_product");
            selectParam.put("sqlType", "select");
            if (!bigtype.equals("省级")&&!bigtype.contains("为农气象服务")) {
                selectParam.put("advCode", DbConfig.advCode);
            }
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<summary_product>>() {
            });
        } catch (Exception e) {
        }
        return listData;
    }

    /***
     * 获取产品发布信息
     * @return
     */
    @Override
    public Object getPublishRecord(String startDate, String endDate, String productType,String areaName) {
        List<PublishRecord> records = new ArrayList<>();
        try {

            if (StringUtil.IsNullOrEmpty(startDate)) {
                Date date = new Date();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                startDate = formatter.format(date);
            } else {
                Date dateStart = null;
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                dateStart = formatter.parse(startDate);
                startDate = formatter.format(dateStart)+" 00:00:00";
            }

            if (StringUtil.IsNullOrEmpty(endDate)) {
                Date date = new Date();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
                endDate = formatter.format(date);
            } else {
                Date dateEnd = null;
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                dateEnd = formatter.parse(endDate);
                endDate = formatter.format(dateEnd) + " 23:59:59";
            }

            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            String strWhere="producttime between '" + startDate + "' and '" + endDate + "'";

            if(!StringUtil.IsNullOrEmpty(productType))
            {
                strWhere+=" and productname='"+productType+"'";
            }
            if(!StringUtil.IsNullOrEmpty(areaName))
            {
                strWhere+=" and publissarea='"+areaName+"'";
            }
            selectRequest.setParam(strWhere);
            selectRequest.setSort(new String[]{"producttime asc"});

            selectParam.put("method", "publish_record");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            records = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<PublishRecord>>() {
            });

        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", records, true);
    }

    /**
     * 获取水位监测最新时间
     *
     * @return
     */
    @Override
    public Object getneartime() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<String, String>();
        List<reservoir_water_info> dataList = new ArrayList<reservoir_water_info>();
        List<rewain> rewains = new ArrayList<>();
        rewain rewain = new rewain();
        selectRequest.setLimit(1);
        selectRequest.setSort(new String[]{"observtime desc"});
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String messages = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(messages, new TypeReference<List<reservoir_water_info>>() {
            });
            rewain.setObservtime(new DateTime(dataList.get(0).getObservtime()).toDateHourString());
            rewain.setObservtimes(new DateTime(dataList.get(0).getObservtime()).AddHours(-24).toDateHourString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rewain;
    }
}
